<template>
  <div class="search">
    <Row>
      <Col>
        <Card>
          <Row class="operation">
            <Row class="operation">
              <Button @click="getDataList" icon="md-refresh">刷新</Button>
            </Row>
          </Row>
          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>
          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
      </Col>
    </Row>
    
  </div>
</template>

<script>
import circleLoading from "@/views/my-components/circle-loading.vue";
export default {
  name: "staffManagement",
  components: {
    circleLoading,
  },
  data() {
    return {
      loading: true, // 表单加载状态
      searchForm: { // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
      },
      submitLoading: false, // 添加或编辑提交状态
      columns: [
        // 表头
        {
          type: "index",
          width: 60,
          align: "center"
        },
        {
          title: "客户名称",
          key: "callerName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "客户手机号",
          key: "callerPhone",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "商家名称",
          key: "calleeName",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "商家手机号",
          key: "calleePhone",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "虚拟号段",
          key: "privateNumber",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "绑定ID",
          key: "subscriptionId",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "创建时间",
          key: "createTime",
          minWidth: 120,
          sortable: false,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          fixed: "right",
          minWidth: 100,
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.remove(params.row);
                    }
                  }
                },
                "解除绑定"
              ),
            ]);
          }
        }
      ],
      data: [], // 表单数据
      total: 0 // 表单数据总数
    };
  },
  methods: {
    init() {
      this.getDataList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
        this.loading = true;
        // 带多条件搜索参数获取表单数据 请自行修改接口
        this.postRequest("/privateNumberAx/getPrivateNumberAxVoList", this.searchForm).then(res => {
            this.loading = false;
            if (res.success) {
              var arr = res.result.dataResult;
              for(let val of arr){
                for(let i in val){
                  (val[i] === null) ? (val[i] = "-") : ""
                }
              }
              this.data = res.result.dataResult;
              this.total = res.result.totalSize;
            } else if (res.code == 201) {
              this.data=[];
              this.total=0;
            }
        });
    },

    remove (v) {
        this.$Modal.confirm({
            title: "删除",
            content: "确认删除该条数据吗？",
            loading: true,
            onOk: ()=> {
                var data = {
                    id: v.id
                }
                this.postRequest("/privateNumberAx/unbindPrivateNum", data).then(res=> {
                    if (res.success) {
                        this.$Message.success("删除成功");
                        this.getDataList();
                        this.$Modal.remove()
                    } else {
                        this.$Message.success(res.message);
                        this.$Modal.remove()
                    }
                })
            }
        })
    }
},
  mounted() {
    this.init();
  }
};
</script>
<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>